<!DOCTYPE html>
<html style="height: 100%;">
<head lang="en">
  <meta charset="UTF-8">
  <title>Login Page | Amaze UI Example</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="format-detection" content="telephone=no">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="stylesheet" href="stylesheets/bootstrap.min.css"/>
  <link rel="stylesheet" href="stylesheets/login.css"/>
  <link rel="stylesheet" type="text/css" href="/stylesheets/toastr.min.css">
  <script src="/javascripts/jquery-3.3.1.min.js"></script>
  <!-- <script src="/javascripts/bootstrap.min.js"></script> -->
  <script src="/javascripts/des.js"></script>
  <script type="text/javascript" src="/javascripts/toastr.min.js"></script>
  
  <style>
   
  </style>
</head>
<body>
<div id="main">
  <div class="login"></div>
  <form class="loginForm">
   <div class="login-top"><p style="margin-left: -24px;">生产管理系统</p>
   <font style="vertical-align: inherit;"><font style="vertical-align: inherit;margin-left: 26px;">
        登录
      </font></font></div>
      <div class="form-group">
        <div class="login-center clearfix">
          <div  class="login-center-img">
             <span class="glyphicon glyphicon glyphicon-user" aria-hidden="true" style="font-size: 24px;top: 12px"></span>
          </div>
          <div class="login-center-input">
             <input type="text" class="form-control" id="username" placeholder="账号" value="xiaozhuang">
          </div>
        </div>
     </div> 
     <div class="form-group">
        <div class="login-center clearfix">
          <div  class="login-center-img">
             <span class="glyphicon glyphicon glyphicon-lock" aria-hidden="true" style="font-size: 24px;top: 12px"></span>
          </div>
          <div class="login-center-input">
             <input type="password" class="form-control" id="password" placeholder="密码" value="xiaozhuang">
          </div>
          </div>
     </div> 
       <div class="form-group">
        <div class="login-center clearfix">
          <div  class="login-center-img">
             <span class="glyphicon glyphicon glyphicon-lock" aria-hidden="true" style="font-size: 24px;top: 12px"></span>
          </div>
          <div class="login-center-input" style="width: 200px;">
             <input type="text" class="form-control" id="imagecode" placeholder="验证码" style="border-radius: 1px;" value="abc">
          </div>
          <div class="login-getcode">
             <img id="getcode" onclick="get_img_code()"  style="width: 100%;height: 100%; background: #fff;" alt="验证码"/>
          </div>
          </div>
     </div> 

      <div class="login-button"><p onclick="Dologin()";><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">确认</font></font></p></div><!-- <font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        登录
      </font></font> -->
       <div class="form-message"></div>
      </form>
</div>
<script type="text/javascript">
$(document).ready(function(){
    get_img_code();
});

function get_img_code(){
        var img = document.getElementById("getcode");
        var randomnum = Math.random();
        img.src="/account/getVerifyimg?"+randomnum;
    }

    function Dologin() {
        var username = $('#username').val();
        var password = $('#password').val();
        var imagecode = $('#imagecode').val();
      console.log("传入的用户名："+username+"密码为+"+password+"验证码为+"+imagecode);
        if (username == "") {
            formMessage('info', "请输入登录帐号!");
        }
        if (password == "") {
            formMessage('password', "请输入登录密码!");
        }
        if (imagecode == "") {
            formMessage('imagecode', "请输入验证码");
        }

        $.ajax({
                 type: "post",
                 async: false,
                 url: "/login",
                 dataType:'json',
                 'data':{
                    "name":username,
                    "password":strEnc(username+','+password+','+imagecode,1,2,3),
                    'vcode':imagecode
                 },
                 success:function(msg){
                    if(msg.statusCode=="200"){
                      console.log('243');
                        location.href = "/";
                    }else{
                       formMessage('error', msg.message);
                        get_img_code();
                        $('#imagecode').val('');
                    }
                 },
                 error:function(XMLHttpRequest, textStatus, errorThrown){
                    if(XMLHttpRequest.status){
                        location.href = "/severError";
                    }
                 }
        });
    }

    function formMessage(type,msg) {
      console.log(type=="info");

      if(type=="info"){
            $('#username').css('color','red').attr('placeholder',msg);
      }else if(type=="password"){
            $('#password').css('color','red').attr('placeholder',msg);
      }else if(type=="imagecode"){
           $('#imagecode').css('color','red').attr('placeholder',msg);
      }else{
      $('.form-message').html('用户名或者账号错误!').css('color','red').css('margin-left','160px').css('margin-top','-310px');
      }
       
        // $('.form-message').append('<div class="form-' + type + '-text">' + msg + '</div>');
    }

  // 参考资料：https://github.com/sunshine940326/canvas-nest
  // class Circle {
  //   //创建对象
  //   //以一个圆为对象
  //   //设置随机的 x，y坐标，r半径，_mx，_my移动的距离
  //   //this.r是创建圆的半径，参数越大半径越大
  //   //this._mx,this._my是移动的距离，参数越大移动
  //   constructor(x, y) {
  //     this.x = x;
  //     this.y = y;
  //     this.r = Math.random() * 10;
  //     this._mx = Math.random();
  //     this._my = Math.random();

  //   }

    // //canvas 画圆和画直线
    // //画圆就是正常的用canvas画一个圆
    // //画直线是两个圆连线，为了避免直线过多，给圆圈距离设置了一个值，距离很远的圆圈，就不做连线处理
    // drawCircle(ctx) {
    //   ctx.beginPath();
    //   //arc() 方法使用一个中心点和半径，为一个画布的当前子路径添加一条弧。
    //   ctx.arc(this.x, this.y, this.r, 0, 360)
    //   ctx.closePath();
    //   ctx.fillStyle = 'rgba(20, 4, 24, 0.6)';
    //   ctx.fill();
    // }

    // drawLine(ctx, _circle) {
    //   let dx = this.x - _circle.x;
    //   let dy = this.y - _circle.y;
    //   let d = Math.sqrt(dx * dx + dy * dy)
    //   if (d < 150) {
    //     ctx.beginPath();
    //     //开始一条路径，移动到位置 this.x,this.y。创建到达位置 _circle.x,_circle.y 的一条线：
    //     ctx.moveTo(this.x, this.y); //起始点
    //     ctx.lineTo(_circle.x, _circle.y); //终点
    //     ctx.closePath();
    //     ctx.strokeStyle = 'rgba(204, 204, 204, 0.3)';
    //     ctx.stroke();
    //   }
    // }

    // 圆圈移动
    // 圆圈移动的距离必须在屏幕范围内
  //   move(w, h) {
  //     this._mx = (this.x < w && this.x > 0) ? this._mx : (-this._mx);
  //     this._my = (this.y < h && this.y > 0) ? this._my : (-this._my);
  //     this.x += this._mx / 2;
  //     this.y += this._my / 2;
  //   }
  // }

  //鼠标点画圆闪烁变动
  // class currentCirle extends Circle {
  //   constructor(x, y) {
  //     super(x, y)
  //   }

    // drawCircle(ctx) {
    //   ctx.beginPath();
      //注释内容为鼠标焦点的地方圆圈半径变化
      //this.r = (this.r < 14 && this.r > 1) ? this.r + (Math.random() * 2 - 1) : 2;
      // this.r = 8;
      // ctx.arc(this.x, this.y, this.r, 0, 360);
      // ctx.closePath();
      // //ctx.fillStyle = 'rgba(0,0,0,' + (parseInt(Math.random() * 100) / 100) + ')'
  //     ctx.fillStyle = 'rgba(255, 77, 54, 0.6)'
  //     ctx.fill();

  //   }
  // }

  //更新页面用requestAnimationFrame替代setTimeout
  // window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;

  // let canvas = document.getElementById('canvas');
  // let ctx = canvas.getContext('2d');
  // let w = canvas.width = canvas.offsetWidth;
  // let h = canvas.height = canvas.offsetHeight;
  // let circles = [];
  // let current_circle = new currentCirle(0, 0)

  // let draw = function() {
  //   ctx.clearRect(0, 0, w, h);
  //   for (let i = 0; i < circles.length; i++) {
  //     circles[i].move(w, h);
  //     circles[i].drawCircle(ctx);
  //     for (j = i + 1; j < circles.length; j++) {
  //       circles[i].drawLine(ctx, circles[j])
  //     }
  //   }
  //   if (current_circle.x) {
  //     current_circle.drawCircle(ctx);
  //     for (var k = 1; k < circles.length; k++) {
  //       current_circle.drawLine(ctx, circles[k])
  //     }
  //   }
  //   requestAnimationFrame(draw)
  // }

  // let init = function(num) {
  //   for (var i = 0; i < num; i++) {
  //     circles.push(new Circle(Math.random() * w, Math.random() * h));
  //   }
  //   draw();
  // }

  // window.addEventListener('load', init(60));

  // window.onmousemove = function(e) {
  //   e = e || window.event;
  //   current_circle.x = e.clientX;
  //   current_circle.y = e.clientY;
  // }

  // window.onmouseout = function() {
  //   current_circle.x = null;
  //   current_circle.y = null;
  // }



</script>


</body>
</html>
